package cn.cms.chuangjia.service.impl;

import java.util.List;

import cn.cms.chuangjia.domain.Article;
import cn.cms.chuangjia.service.IArticleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.cms.chuangjia.mapper.ArticleMapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * 文章Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-18
 */
@Service
@Transactional(readOnly = true)
public class ArticleServiceImpl implements IArticleService
{
    @Autowired
    private ArticleMapper articleMapper;

    /**
     * 查询文章
     * 同时更新访问次数
     * @param id 文章主键
     * @return 文章
     */
    @Transactional(readOnly = false)
    @Override
    public Article selectArticleById(Integer id)
    {
        //读取,并更新访问次数
        articleMapper.incrVisitCount(id);
        return articleMapper.selectArticleById(id);
    }

    /**
     * 查询文章列表
     * 
     * @param article 文章
     * @return 文章
     */
    @Override
    public List<Article> selectArticleList(Article article)
    {
        return articleMapper.selectArticleList(article);
    }

    /**
     * 新增文章
     * 
     * @param article 文章
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int insertArticle(Article article)
    {
        return articleMapper.insertArticle(article);
    }

    /**
     * 修改文章
     * 
     * @param article 文章
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int updateArticle(Article article)
    {
        return articleMapper.updateArticle(article);
    }

    /**
     * 批量删除文章
     * 
     * @param ids 需要删除的文章主键
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteArticleByIds(Integer[] ids)
    {
        return articleMapper.deleteArticleByIds(ids);
    }

    /**
     * 删除文章信息
     * 
     * @param id 文章主键
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteArticleById(Integer id)
    {
        return articleMapper.deleteArticleById(id);
    }

    @Override
    public List<Article> selectArticleByMenu(Integer id) {
        return this.articleMapper.selectArticleByMenu(id);
    }

    @Override
    public List<Article> findTuijianProduct(int size) {
        return this.articleMapper.findArticles("PRODUCT",size);

    }

    @Override
    public List<Article> findNews(int size) {
        return this.articleMapper.findArticles("NEWS",size);
    }

    @Override
    public List<Article> findProduct(int size) {
        return this.articleMapper.findArticles("PRODUCT",size);

    }

    @Override
    public List<Article> findCustomers(int size) {
        return this.articleMapper.findArticles("CUSTOMERS",size);

    }
}
